/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shooter;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.math.Vector2;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Unni Vemanchery Mana
 */
public class WorldController {
    
    enum Keys {
	LEFT, RIGHT, JUMP, FIRE
	}

	private World 	world;

        private Player player;
        
	static Map<Keys, Boolean> keys = new HashMap<WorldController.Keys, Boolean>();
	static {
		keys.put(Keys.LEFT, false);
		keys.put(Keys.RIGHT, false);
		keys.put(Keys.JUMP, false);
		keys.put(Keys.FIRE, false);
	};

	public WorldController(World world) {
		this.world = world;
                this.player = world.getPlayer();
	}

	// ** Key presses and touches **************** //

	public void leftPressed() {
		keys.get(keys.put(Keys.LEFT, true));
	}

	public void rightPressed() {
		keys.get(keys.put(Keys.RIGHT, true));
	}

	public void jumpPressed() {
		keys.get(keys.put(Keys.JUMP, true));
	}

	public void firePressed() {
            player.getFiringSound().play();
           player.getBulletManager().getBullet((int)player.getPosition().x, (int)player.getPosition().y);
	   keys.get(keys.put(Keys.FIRE, true));
	}

	public void leftReleased() {
		keys.get(keys.put(Keys.LEFT, false));
	}

	public void rightReleased() {
		keys.get(keys.put(Keys.RIGHT, false));
	}

	public void jumpReleased() {
		keys.get(keys.put(Keys.JUMP, false));
	}

	public void fireReleased() {
		keys.get(keys.put(Keys.FIRE, false));
	}

	/** The main update method **/
	public void update(float delta) {
		processInput();
             //   player.update(delta);
	}
        public void touchDown(int x, int y, int pointer, int button){
            System.out.println(" pointer " + pointer);
            System.out.println(" button " + button);
            if(x < 50) {
                System.out.println("touch down event");
                player.getBulletManager().getBullet((int)player.getPosition().x, (int)player.getPosition().y);
            }
            
            /*
            if(x > 400 && y > 160 ){
                System.out.println("right...");
                player.moveRight();
            }
            if(x > 400 && y < 160 ){
                System.out.println("left...");
                player.moveLeft();
            }
             * */
             
        }

        public void touchDragged(int i, int i1, int i2){
            //player.setPosition(new Vector2(i1,i2));
        }
	/** Change player state and parameters based on input controls **/
	private void processInput() {
                if(Gdx.input.isTouched(0)){
                    System.out.println("is touched.....");
                    System.out.println(Gdx.input.getX(0));
                    System.out.println(Gdx.input.getY(0));
                    int x = Gdx.input.getX(0);
                    int y = Gdx.input.getY(0);
                    
                    if(x > 400 && y > 200)
                    player.moveRight();
                    
                    if(x > 400 && y < 200)
                    player.moveLeft();
                    
                }
                
		if (keys.get(Keys.LEFT)) {
                    player.moveLeft();
		}
		if (keys.get(Keys.RIGHT)) {
                    player.moveRight();
		}
	}
       
}
